package 泛型.反省擦除;

class Building {
}

class House extends Building {
}

public class ClassTypeCapture<T> {
	// 类型标签，可以识别类型
	Class<T> kind;

	public ClassTypeCapture(Class<T> kind) {
		this.kind = kind;
	}

	public boolean f(Object arg) {
		return kind.isInstance(arg);
	}

	public static void main(String[] args) {
		ClassTypeCapture<Building> ctt1 = new ClassTypeCapture<>(Building.class);
		ClassTypeCapture<House> ctt2 = new ClassTypeCapture<>(House.class);

		System.out.println(ctt1.f(new Building()));//true
		System.out.println(ctt1.f(new House())); //true
		System.out.println(ctt2.f(new Building())); //false
		System.out.println(ctt2.f(new House())); //true


	}
}
